package com.example.child_protection.service.impl;

import com.example.child_protection.dao.UserDao;
import com.example.child_protection.dto.base.BaseRequestDTO;
import com.example.child_protection.dto.info.UserInfoDTO;
import com.example.child_protection.dto.response.UserPageResponseDTO;
import com.example.child_protection.model.UserModel;
import com.example.child_protection.service.UserService;
import com.example.child_protection.service.base.MyBaseService;
import com.example.child_protection.service.base.MyServiceExecutor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class UserServiceImpl extends MyBaseService implements UserService {

    @Autowired
    public UserDao userDao;

    @Override
    public UserPageResponseDTO findPage(BaseRequestDTO requestDTO){
        /*return this.service(requestDTO, UserPageResponseDTO.class, new MyServiceExecutor<BaseRequestDTO, UserPageResponseDTO>() {
            @Override
            protected UserPageResponseDTO myprocess(BaseRequestDTO requestDTO) throws Exception {*/
                UserPageResponseDTO res = new UserPageResponseDTO();
                List<UserModel> resVO = userDao.findPage(new UserModel());
                UserInfoDTO i = null;
                if(null != resVO && resVO.size()>0){
                    List<UserInfoDTO> infos = new ArrayList<>();
                    for(UserModel u:resVO){
                        i = new UserInfoDTO();
                        BeanUtils.copyProperties(u,i);
                        infos.add(i);
                    }
                    //res.setInfos(infos);
                }
                res.successfully();
                return res;
            /*}
        });*/
    }
}
